package com.wanmait.wanmarecruit.webController;

import com.wanmait.wanmarecruit.entity.EducationalExperience;
import com.wanmait.wanmarecruit.entity.StudentCadreExperience;
import com.wanmait.wanmarecruit.entity.User;
import com.wanmait.wanmarecruit.entity.WorkExperience;
import com.wanmait.wanmarecruit.service.UserService;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

@Controller
@RequestMapping("web")
public class WebPersonalUserDetailController {

    @Resource
    private UserService userService;

    @RequestMapping("/companies/companiesCandidatesDetail/{userId:\\d+}")
    public ModelAndView goCompanyCandidatesDetail(@PathVariable Integer userId)
    {
        ModelAndView modelAndView = new ModelAndView();
        User user = userService.getUserMessageByUserId(userId);
        modelAndView.addObject("Users",user);
        List<EducationalExperience> educationalExperienceList = new ArrayList<>(user.getEducationalExperiences());
        List<StudentCadreExperience> studentCadreExperienceList = new ArrayList<>(user.getStudentCadreExperiences());
        List<WorkExperience> workExperienceList = new ArrayList<>(user.getWorkExperiences());
        Collections.sort(educationalExperienceList);
        Collections.sort(studentCadreExperienceList);
        Collections.sort(workExperienceList);
        modelAndView.addObject("educationalExperienceList",educationalExperienceList);
        modelAndView.addObject("studentCadreExperienceList",studentCadreExperienceList);
        modelAndView.addObject("workExperienceList",workExperienceList);
        modelAndView.setViewName("/web/companies/companiesCandidatesDetail");
        return modelAndView;
    }
}
